<?php


namespace app\api\controller\v1;


use app\api\vaildate\IDCollection;
use app\api\model\Theme as ThemeModel;
use app\api\vaildate\IDMustBePostiveInt;
use app\lib\exception\ThemeException;

class Theme
{
    /*
     * 获取主题数据
     * @url /theme?ids=1,2,3
     * @http GET
     * @ids 输入以,分割的正整数
     * @return 一组theme模型
     */
    public function getSimpleList($ids = '')
    {
        (new IDCollection())->goCheck();
//        $result = ThemeModel::with('topicImg,headImg')->select($ids);
        $result = ThemeModel::getThemeList($ids);
        if ($result->isEmpty()) {
            throw new ThemeException();
        }
        return $result;
    }

    /*
     * 获取ID主题数据
     * @url /theme/:id
     * @http GET
     * @return theme模型
     */
    public function getComplexOne($id)
    {
        (new IDMustBePostiveInt())->goCheck();
        $result = ThemeModel::getThemeWithProdust($id);
        if (!$result) {
            throw new ThemeException();
        }
        return $result;
    }

}